package com.sc.socket.udpgroup;

/**
 * @author shuc001
 * @Date 2019-02-03 16:20
 */
public class MessageCreator {
    public static final String SN_HEADER = "收到暗号,我是:";
    public static final String PORT_HEADER = "这是暗号,请回电到端口:";

    public static String buildWithPort(int port){
        return PORT_HEADER+port;
    }

    public static int parseCode(String data ){
        if(data.startsWith(PORT_HEADER)){
            return Integer.parseInt(data.substring(PORT_HEADER.length()));
        }
        return -1;
    }

    public static String buildWithSN(String sn){
        return SN_HEADER+sn;
    }

    public static String parseSN(String sn){
        if(sn.startsWith(SN_HEADER)){
            return sn.substring(SN_HEADER.length());
        }
        return null;
    }
}
